﻿<local:LayoutAwarePage
    x:Class="yavc.Metro.Pages.StartPage"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:yavc.Metro.Pages"
    xmlns:con="using:yavc.Metro.Controls"
    xmlns:conv="using:yavc.Metro.Converters">
    <Page.Resources>
        <conv:VisibilityBooleanConverter x:Key="loadedVis"
                                         TrueVisibility="Collapsed"
                                         FalseVisibility="Visible"
                                         DefaultVisibility="Visible" />
        <conv:ScaleValue x:Key="scale" x:Name="theScale" Value="{Binding Value, Source={StaticResource BaseValue}, Mode=TwoWay}" />
    </Page.Resources>

    <Grid Background="{StaticResource MetroBackgroundBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <con:HeaderControl HeaderText="Yamaha AV Controller" 
                           HeaderFontSize="{Binding Source={StaticResource scale}, Path=Value, Converter={StaticResource convMetroTitleFontSize}}"
                           SubHeaderText="Device Select" 
                           SubHeaderFontSize="{Binding Source={StaticResource scale}, Path=Value, Converter={StaticResource convMetroTextLargeFontSize}}" />
        
        <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="20,50" Grid.Row="1">
            <StackPanel Orientation="Horizontal">
                <Button Content="Add Device" Click="Button_AddDevice_Click" />
                <Button Content="Refresh Devices" Click="Button_Refresh_Click" />
            </StackPanel>
        </StackPanel>
        
        <Grid Grid.Row="2" Margin="12,0">
            <ItemsControl x:Name="lbReceivers" ItemsSource="{Binding Devices}" HorizontalAlignment="Center">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Button Click="ViewDevice_Click" Margin="0,0,0,17" BorderThickness="0" Padding="15" 
                                HorizontalContentAlignment="Left">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding FriendlyName}" 
                                           FontSize="{Binding Source={StaticResource scale}, Path=Value, Converter={StaticResource convMetroTextLargeFontSize}}"
                                           Grid.Column="1" VerticalAlignment="Center" />
                                <ProgressBar
                                    Minimum="0" Maximum="1" Grid.Row="1" Grid.ColumnSpan="2" HorizontalAlignment="Stretch"
                                    IsIndeterminate="{Binding IsIndeterminate}"
                                    Foreground="{StaticResource MetroForegroundBrush}"
                                    Value="{Binding PercentageLoaded}"  
                                    Visibility="{Binding IsLoaded, Converter={StaticResource loadedVis}}" />
                                <TextBlock 
                                    Grid.Row="2" VerticalAlignment="Top" Grid.Column="1" 
                                    Text="{Binding LoadingMessage}" 
                                    Foreground="{StaticResource MetroForegroundBrush}"
                                    Style="{StaticResource BasicTextStyle}"
                                    Visibility="{Binding IsLoaded, Converter={StaticResource loadedVis}}" />

                                <Image VerticalAlignment="Center" Margin="10" 
                                       Source="{Binding ImageUri, Converter={StaticResource imgConv}}" />
                            </Grid>
                        </Button>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
        <VisualStateManager.VisualStateGroups>
            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="Value" Storyboard.TargetName="theScale" 
                                         To="{Binding Source={StaticResource DefaultFullScreenLandscapeScale}}" 
                                         EnableDependentAnimation="True" 
                                         BeginTime="0" Duration="0:0:0.25" />
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Filled" />
                <VisualState x:Name="FullScreenPortrait" />
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetProperty="Value" Storyboard.TargetName="theScale" 
                                         To="3.75" 
                                         EnableDependentAnimation="True"
                                         BeginTime="0" Duration="0:0:0.25" />
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</local:LayoutAwarePage>